package com.example.schoolenterprisealliance.adapter;
//联盟成员
import android.os.StrictMode;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.schoolenterprisealliance.R;
import com.example.schoolenterprisealliance.bean.Admin;
import com.example.schoolenterprisealliance.io.MyBitmap;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
public class IntroduceAdapter extends BaseMultiItemQuickAdapter<Admin.DataBean,BaseViewHolder> {
    private List<Admin.DataBean> data=new ArrayList<>();
    public IntroduceAdapter(List<Admin.DataBean> data) {
        super(data);
        this.data=data;
        addItemType(Admin.DataBean.LEFT, R.layout.item_admin_left);
        addItemType(Admin.DataBean.RIGHT, R.layout.item_admin_right);
    }
    @Override
    protected void convert(@NonNull BaseViewHolder helper, Admin.DataBean item) {
        StrictMode.setThreadPolicy(new
                StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
        StrictMode.setVmPolicy(
                new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

        helper.addOnClickListener(R.id.button_left);
        helper.addOnClickListener(R.id.button_right);
        Log.e("IntroduceAdapter",item.toString());
                switch (item.getItemType()) {
                    case Admin.DataBean.LEFT:
                        try {
                            helper.setText(R.id.tv_name_left, item.getUsername())
                                    .setText(R.id.tv_introduce_left, item.getContext())
                                    .setText(R.id.tv_position_left,item.getPosition())
                                        .setImageBitmap(R.id.iv_left,MyBitmap.getBitmap(item.getLogoUrl()));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

//                        Glide.with(context).load(path).into((ImageView) helper.getView(R.id.iv_left));
                        break;
                    case Admin.DataBean.RIGHT:
                        try {
                            helper.setText(R.id.tv_name_right, item.getUsername())
                                    .setText(R.id.tv_introduce_right, item.getContext())
                                    .setText(R.id.tv_position_right,item.getPosition())
                                    .setImageBitmap(R.id.iv_right, MyBitmap.getBitmap(item.getLogoUrl()));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        break;
                }

        }




}

